﻿ 
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using Org.Apache.Http.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiMeiJiaLibModel.Business;
using YiMeiJiaLibModel.Business.Dto;
using YiMeiJiaLibModel.Config;
using YiMeiJiaLibModel.Enums;
using YiMeiJiaService.Assembly;
using YiMeiJiaService.IService;

namespace YiMeiJiaApp.Pages.Account
{
    public partial class Me
    {

        #region 服务组件

        [Inject] private IAcccount _account { get; set; }
        [Inject] private IGoods _goods { get; set; }

        [Inject] protected NavigationManager Navigation { get; set; }


        [Inject] protected IJSRuntime JSRuntime { get; set; }
        #endregion 



        #region 绑定数据
        public CoreCmsUserDto _userData { get; set;  }

        #endregion



        /// <summary>
        /// 加载事件
        /// </summary>
        /// <returns></returns>
        protected override async Task OnInitializedAsync()
        {

            try
            {
               
                string msg = "all";
                var usr =await  _HttpClient.Action<CoreCmsUserDto>("获取用户信息", new { }, true);
                if (!usr.status  && usr.code ==401)
                {
                    await EvalJs.ExJs().Toast(JSRuntime, usr.msg, EmToast.cancel);
                    Navigation.NavigateTo("/Account/Loin");
                    return;
                }else if (!usr.status)
                {
                    await EvalJs.ExJs().alert(JSRuntime, usr.msg);
                    return; 
                }
                _userData = usr.data;
                if (string.IsNullOrEmpty(_userData.avatarImage))
                {
                    _userData.avatarImage = $"{ApiConf.CND}/Images/Icon/logo2.png";
                }
                var n = "";
            }
            catch (Exception ex)
            {
                throw;
            }
            await base.OnInitializedAsync();
        }
    }
}
